﻿using System.Collections.Generic;
using System.Linq;
using CodeLibrary.Extensions.Common.Collections;
using CodeLibrary.Extensions.Common.Collections.SortStrategies;

namespace CodeLibrary.Extensions
{
    public static class IEnumerableExtensions
    {
        public static IEnumerable<int> Sort(this IEnumerable<int> val, SortMethod sortMethod)
        {
            IList<int> list = val.ToList();
            switch (sortMethod)
            {
                case SortMethod.Bubble:
                    BubbleSort.Sort(ref list);
                    break;
                case SortMethod.Insertion:
                    InsertionSort.Sort(ref list);
                    break;
                case SortMethod.Selection:
                    SelectionSort.Sort(ref list);
                    break;
            }
            return list;
        }
        
        public static IEnumerable<long> Sort(this IEnumerable<long> val, SortMethod sortMethod)
        {
            IList<long> list = val.ToList();
            switch (sortMethod)
            {
                case SortMethod.Bubble:
                    BubbleSort.Sort(ref list);
                    break;
                case SortMethod.Insertion:
                    InsertionSort.Sort(ref list);
                    break;
                case SortMethod.Selection:
                    SelectionSort.Sort(ref list);
                    break;
            }
            return list;
        }
        
        public static IEnumerable<decimal> Sort(this IEnumerable<decimal> val, SortMethod sortMethod)
        {
            IList<decimal> list = val.ToList();
            switch (sortMethod)
            {
                case SortMethod.Bubble:
                    BubbleSort.Sort(ref list);
                    break;
                case SortMethod.Insertion:
                    InsertionSort.Sort(ref list);
                    break;
                case SortMethod.Selection:
                    SelectionSort.Sort(ref list);
                    break;
            }
            return list;
        }
        
        public static IEnumerable<float> Sort(this IEnumerable<float> val, SortMethod sortMethod)
        {
            IList<float> list = val.ToList();
            switch (sortMethod)
            {
                case SortMethod.Bubble:
                    BubbleSort.Sort(ref list);
                    break;
                case SortMethod.Insertion:
                    InsertionSort.Sort(ref list);
                    break;
                case SortMethod.Selection:
                    SelectionSort.Sort(ref list);
                    break;
            }
            return list;
        }
        
        public static IEnumerable<double> Sort(this IEnumerable<double> val, SortMethod sortMethod)
        {
            IList<double> list = val.ToList();
            switch (sortMethod)
            {
                case SortMethod.Bubble:
                    BubbleSort.Sort(ref list);
                    break;
                case SortMethod.Insertion:
                    InsertionSort.Sort(ref list);
                    break;
                case SortMethod.Selection:
                    SelectionSort.Sort(ref list);
                    break;
            }
            return list;
        }
    }
}
